<template>
  <div class="mod-live-liveRoom">
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @search-reset="searchReset"
      @refresh-change="refreshChange"
    >
      <template slot-scope="scope" slot="menuLeft">
        <el-button
          icon="el-icon-plus"
          type="primary"
          size="small"
          v-if="isAuth('live:liveRoom:save')"
          @click="addOrUpdateHandle()"
          >{{ $t("crud.addTitle") }}</el-button
        >
        <span style="color: red"
          >{{ $t("live.numLiveBroRoom") }}：{{ shopNum
          }}{{ $t("live.times") }},{{ $t("live.subPlatRemLimi") }}{{ totalNum
          }}{{ $t("live.times") }}</span
        >
      </template>
      <template slot-scope="scope" slot="liveStatus">
        <el-tag v-if="scope.row.liveStatus === 0" size="small" type="danger">{{
          $t("productComm.waitPass")
        }}</el-tag>
        <el-tag v-else size="small">{{ $t("productComm.pass") }}</el-tag>
      </template>
      <template slot="search">
        <el-col :md="10" :xs="24">
          <el-form-item :label="this.$i18n.t('live.startTime')">
            <el-date-picker
              v-model="dateRange"
              type="datetimerange"
              :range-separator="this.$i18n.t('date.tip')"
              value-format="yyyy-MM-dd HH:mm:ss"
              :start-placeholder="this.$i18n.t('date.start')"
              :end-placeholder="this.$i18n.t('date.end')"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </template>
      <template slot-scope="scope" slot="liveStatus">
        <el-tag
          v-if="scope.row.liveStatus === 101"
          size="small"
          type="danger"
          >{{ $t("live.liveing") }}</el-tag
        >
        <el-tag v-if="scope.row.liveStatus === 102" size="small">{{
          $t("live.noStart")
        }}</el-tag>
        <el-tag v-if="scope.row.liveStatus === 103" size="small">{{
          $t("live.over")
        }}</el-tag>
        <el-tag v-if="scope.row.liveStatus === 104" size="small">{{
          $t("live.banned")
        }}</el-tag>
        <el-tag v-if="scope.row.liveStatus === 105" size="small">{{
          $t("live.pause")
        }}</el-tag>
        <el-tag v-if="scope.row.liveStatus === 106" size="small">{{
          $t("live.abnormal")
        }}</el-tag>
        <el-tag v-if="scope.row.liveStatus === 107" size="small">{{
          $t("live.expired")
        }}</el-tag>
      </template>
      <template slot-scope="scope" slot="roomTop">
        <el-tag v-if="scope.row.roomTop === 0" size="small">{{
          $t("live.notPinned")
        }}</el-tag>
        <el-tag
          v-else-if="scope.row.roomTop === 1"
          size="small"
          type="success"
          >{{ $t("live.pinned") }}</el-tag
        >
      </template>
      <template slot-scope="scope" slot="menu">
        <!-- <el-button
          icon="el-icon-edit"
          size="small"
          type="text"
          @click="addOrUpdateHandle(scope.row.id)"
        >{{$t("crud.updateBtn")}}</el-button>-->
        <el-button
          icon="el-icon-edit"
          v-if="isAuth('live:liveRoom:see') && scope.row.roomToolsVo.closeGoods == 0"
          size="small"
          type="text"
          @click="seeProd(scope.row)"
          >{{ $t("live.viewProduct") }}</el-button
        >
        <el-button
          icon="el-icon-edit"
          size="small"
          type="text"
          v-if="isAuth('live:liveRoom:info')"
          @click="addOrUpdateHandle(scope.row.id)"
          >{{ $t("live.viewLRoomInfo") }}</el-button
        >
        <!-- <el-button
          type="text"
          icon="el-icon-delete"
          size="small"
          @click="deleteHandle(scope.row.id)"
        >{{$t("text.delBtn")}}</el-button>-->
      </template>
    </avue-crud>
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="refreshChange"
    ></add-or-update>
    <play-back
      v-if="playBackVisible"
      ref="playBack"
      @refreshDataList="refreshChange"
    ></play-back>
    <!-- <import-prod v-if="importProdVisible" ref="importProd" @refreshDataList="refreshChange"></import-prod> -->
    <!-- <room-prod v-if="liveRoomVisible" ref="roomProd" @refreshDataList="refreshChange"></room-prod> -->
  </div>
</template>

<script>
import { tableOption } from '@/crud/live/liveRoom'
import AddOrUpdate from './liveRoom-add-or-update'
import importProd from './liveRoom-import-prod'
import playBack from './liveRoom-play-back'

// import roomProd from './live-room-prod'
export default {
  data () {
    return {
      dataList: [],
      prods: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      totalNum: 0,
      shopNum: 0,
      dateRange: [],
      tableOption: tableOption,
      addOrUpdateVisible: false,
      seeProdVisible: false,
      playBackVisible: false,
      importProdVisible: false,
      liveRoomVisible: false
    }
  },
  components: {
    AddOrUpdate,
    importProd,
    playBack
    // roomProd,
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getDataList (page) {
      this.getAddRoomNum()
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/multishop/live/liveRoom/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize,
              'startTime': this.dateRange === null ? null : this.dateRange[0], // 开始时间
              'endTime': this.dateRange === null ? null : this.dateRange[1] // 结束时间
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 获取剩余可新增得数量
    getAddRoomNum () {
      this.$http({
        url: this.$http.adornUrl('/multishop/live/liveRoom/getAddRoomNum'),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.shopNum = data.shopNum
        this.totalNum = data.totalNum
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 查看直播回放
    seePlayBack (id) {
      this.playBackVisible = true
      this.$nextTick(() => {
        this.$refs.playBack.init(id)
      })
    },
    // 导入商品
    importProd (id) {
      this.importProdVisible = true
      this.$nextTick(() => {
        this.$refs.importProd.init(id)
      })
    },
    // 新增 / 修改
    seeProd (room) {
      this.$router.push({
        path: '/roomProds',
        query: { id: room.id, status: room.liveStatus }
      })
    },
    deleteHandle (id) {
      this.$confirm(this.$i18n.t('admin.isDeleOper') + '?', this.$i18n.t('text.tips'), {
        confirmButtonText: this.$i18n.t('crud.filter.submitBtn'),
        cancelButtonText: this.$i18n.t('crud.filter.cancelBtn'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/multishop/live/liveRoom/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    // 清空自定义数据
    searchReset () {
      this.dateRange = []
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.page.currentPage = 1
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.page.currentPage = 1
      this.searchForm = params
      this.getDataList(this.page)
    }
  }
}
</script>
<style lang="scss">
.mod-live-liveRoom {
}
</style>
